package com.guiguli.ObjectDemo;

import java.util.Objects;

//我们所有的类都继承自object，它有着一些方法，我们可以重写

public class Student {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    protected Student clone() throws CloneNotSupportedException {
        return new Student(this.name,this.age);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;//先判断地址值
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;//强转
        return age == student.age && Objects.equals(name, student.name);//比较属性
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student() {
    }
}
